package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.Competition;
import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.ICompetitionService;
import cn.edu.lingnan.service.IStudentService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/admin/updateCom")
public class UpdateCompeteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1
        String cid = req.getParameter("cid");
        System.out.println("[Debug 060] the competitionId is "+cid);
        String cname = req.getParameter("cname");
        String description = req.getParameter("description");
        String start_time = req.getParameter("start_time");
        String end_time = req.getParameter("end_time");
        Competition competition = new Competition();
        competition.setId(Integer.parseInt(cid));
        competition.setName(cname);
        competition.setDescription(description);
        competition.setStart_time(start_time);
        competition.setEnd_time(end_time);
        System.out.println(competition);
        //2
        ICompetitionService service = new ICompetitionService();
        service.updateCompetitionById(competition);
        //3
        resp.sendRedirect("/queryAllCompete");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
